import Vue from 'vue'
import VueRouter from 'vue-router'
import Store from '../store/index'
import Home from '../views/Home.vue'

Vue.use(VueRouter)
const router = new VueRouter({
  base: process.env.BASE_URL,
  // mode: "history",
  routes: [
    {
      path: "*",
      redirect: "/login"
    },
    {
      path: '/login',
      name: "Login",
      component: require('../views/children/Login').default
    },
    {
      path: '/index',
      name: 'Home',
      component: Home
    },
    {
      path: "/home",
      name: "index",
      component: () => import('../views/index')
    },
    {
      path: "/dir",
      name: "Driver",
      component: () => import('../views/children/Driver')
    },
    {
      path: "/pay",
      name: "Payment",
      component: () => import('../views/children/Payment')
    },
    {
      path: "/eval",
      name: "evalute",
      component: () => import('../views/children/evalute')
    },
    {
      path: "/regis",
      name: "Register",
      component: () => import('../views/children/Register')
    },
    {
      path: "/order",
      name: "order",
      component: () => import('../views/children/order')
    },
    {
      path: '/cancel',
      name: 'cancellation',
      component: () => import('../views/children/cancellation')
    },
    {
      path: '/qb',
      name: 'qianbao',
      component: () => import('../views/children/项目/qianbao')
    },
    {
      path: "/cz",
      name: 'chong',
      component: () => import('../views/children/chong'),
    },
    {
      path: '/ti',
      name: "tixian",
      component: () => import('../views/children/项目/tixian')
    },
    {
      path: '/red',
      name: "Record",
      component: () => import('../views/children/项目/Record')
    },
    {
      path: '/many',
      name: "Many",
      component: () => import('../views/children/项目/Many')
    },
    {
      path: "/siji",
      name: "sijiba",
      component: () => import('../views/children/sijiba')
    },
    {
      path: "/zhao",
      name: "Zhaomu",
      component: () => import('../views/children/Zhaomu')
    },
    {
      path: "/Shenqing",
      name: "Shenqing",
      component: () => import('../views/children/Shenqing')
    },
    {
      path: "/xieyi",
      name: "xieyi",
      component: () => import('../views/children/Xieyi')
    },
    {
      path: '/yinsi',
      name: 'yinsi',
      component: () => import('../views/children/Yinsi')
    },
    {
      path: '/setup',
      name: "SetUp",
      component: () => import('../views/children/SetUp')
    },
    {
      path: '/passWord',
      name: "PassWord",
      component: () => import('../views/children/SetUps/PassWord')
    },
    {
      path: '/adsuss',
      name: "Adsuss",
      component: () => import('../views/children/SetUps/Adsuss')
    },
    {
      path: '/agreement',
      name: "Agreement",
      component: () => import('../views/children/SetUps/Agreement')
    },
    {
      path: '/privacypolicy',
      name: "PrivacyPolicy",
      component: () => import('../views/children/SetUps/PrivacyPolicy')
    },
    {
      path: '/about',
      name: 'About',
      component: () => import('../views/children/SetUps/About')
    },
    {
      path: '/datas',
      name: "",
      component: () => import('../views/children/MyData')
    },
    {
      path: '/zhi',
      name: "zhi",
      component: () => import('../views/children/Zhi')
    },
    {
      path: "/todo",
      name: "todolist",
      component: () => import('../views/children/dituba')
    },
    {
      path: "/qd",
      name: "Qd",
      component: () => import('../views/children/driver/Qd')
    },
    {
      path: "/sb",
      name: "Sb",
      component: () => import('../views/children/driver/Sb')
    },
    {
      path: "/ji",
      name: "Ji",
      component: () => import('../views/children/driver/Ji')
    },
    {
      path: "/jiazai",
      name: "Jiazai",
      component: () => import('../views/children/driver/Jiazai')
    },
    {
      path: "/zhili",
      name: "Zhi",
      component: () => import('../views/children/driver/Zhi')
    },
    {
      path: "/recev",
      name: "Receiving",
      component: () => import('../views/children/driver/Receiving')
    },
    {
      path: '/delete',
      name: "deleteorder",
      component: () => import('../views/children/driver/deleteorder')
    }
  ]
})

router.beforeEach((to, from, next) => {
  //登录信息来自于vuex
  const stateIsUp = Store.state.userInfo.isUp;
  // console.log(state);
  if (to.path == '/home' && stateIsUp == false) {
    next('/')
  } else if ((to.path == '/' || to.path == '/login') && stateIsUp == true) {
    //由于手动输入地址,to和from的地址重复,导致递归,next函数中不能写form.path,需要手动写一个准确的地址
    next('/home')
  } else {
    next()
  }

})


export default router
